package just.stuff.morsels.ui.search;

import java.io.IOException;
import java.util.List;

import just.stuff.morsels.MorselApplication;
import just.stuff.morsels.objects.Morsel;
import just.stuff.morsels.ui.BasePage;
import just.stuff.morsels.ui.morsel.MorselList;

import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.queryParser.ParseException;
import org.apache.wicket.PageParameters;
import org.apache.wicket.model.Model;

/**
 * Search result page.
 *
 */
public class SearchResults extends BasePage {

	public static final String QUERY_PARAM = "query";

	public SearchResults( PageParameters params ) throws CorruptIndexException, ParseException, IOException {
		this( params.getString( QUERY_PARAM) );
	}
	
	/**
	 * Internal non-bookmarkable constructor
	 * @param query
	 * @throws CorruptIndexException
	 * @throws ParseException
	 * @throws IOException
	 */
	private SearchResults( final String query ) throws CorruptIndexException, ParseException, IOException {
		final List<Morsel> morsels = MorselApplication.dataSource().find( query );
		add( new MorselList( "list", Model.ofList( morsels )));

	}
	
}
